package com.report;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.MergeCellRule;
import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.data.Rows;
import com.deepoove.poi.data.Tables;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class demo {


    public static void main(String[] args) throws IOException {

        /*String a ="{\"header\":[{\"key\":\"989f6a38b3a341e991d5df754d74ee54-key\",\"label\":\"主键\",\"config\":{\"width\":150,\"type\":\"autocomplete\",\"visibleRows\":10,\"strict\":false,\"className\":\"cpas-map-model\"}},{\"key\":\"42f0b1e27ca84ca0bb8894c06833d95f\",\"label\":\"票据种类\",\"config\":{\"width\":176,\"type\":\"text\",\"ht\":1,\"keyword\":true,\"bl\":2}},{\"key\":\"4b58fb5beb2449f29ccf1891854bf880\",\"label\":\"期末数\",\"config\":{\"width\":150,\"type\":\"numeric\",\"ht\":2,\"validator\":\"cpasFormulaValidator\",\"bl\":2},\"children\":[{\"key\":\"1eef4a9029024465ac26aab95dfa0fca\",\"label\":\"账面余额\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2}},{\"key\":\"d0865bbdb07b4c759d4a211026039b16\",\"label\":\"坏账准备\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2}},{\"key\":\"d2831cac10234383b8bd9ecc0921bd81\",\"label\":\"账面价值\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2}}]},{\"key\":\"b0f56d269f9e490bb0f308ec911d2ab8\",\"label\":\"期初数\",\"config\":{\"type\":\"numeric\",\"width\":150,\"ht\":2,\"validator\":\"cpasFormulaValidator\",\"bl\":2},\"children\":[{\"key\":\"09d80c626e95484d89acfef624ce5145\",\"label\":\"账面余额\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2}},{\"key\":\"fe05f974750f4759b7fc1f989b55d616\",\"label\":\"坏账准备\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2}},{\"key\":\"e3d9a409ca804966aa3b0818eb523162\",\"label\":\"账面价值\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2}}]},{\"key\":\"c24cb6f20d31426e8151ea607953e18e-config\",\"label\":\"rowConfig\",\"config\":{\"width\":150,\"type\":\"text\"}}],\"data\":[[\"\\\\\",\"票据种类\",\"期末-账面余额\",\"期末-坏账准备\",\"期末-账面价值\",\"期初-账面余额\",\"期初-坏账准备\",\"期初-账面价值\",\"{\\\"rId\\\":\\\"8bd173afb5b34fa2a5328e19b2238614\\\",\\\"className\\\":\\\"cpas-map-model\\\",\\\"type\\\":\\\"autocomplete\\\",\\\"visibleRows\\\":10,\\\"strict\\\":false}\"],[\"银行承兑汇票\",\"银行承兑汇票\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-银行承兑汇票\\\",\\\"期末数|未审数\\\",\\\"本年\\\")\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-银行承兑汇票\\\",\\\"期末数|账项调整\\\",\\\"本年\\\")\",\"=C2-D2\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-银行承兑汇票\\\",\\\"期初数|未审数\\\",\\\"本年\\\")\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-银行承兑汇票\\\",\\\"期初数|账项调整\\\",\\\"本年\\\")\",\"=F2-G2\",\"{\\\"rId\\\":\\\"d1b72f7572c8487fb435ae745421608f\\\",\\\"r_tag\\\":[\\\"TOP--1468\\\"]}\"],[\"商业承兑汇票\",\"商业承兑汇票\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-商业承兑汇票\\\",\\\"期末数|未审数\\\",\\\"本年\\\")\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-商业承兑汇票\\\",\\\"期末数|账项调整\\\",\\\"本年\\\")\",\"=C3-D3\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-商业承兑汇票\\\",\\\"期初数|未审数\\\",\\\"本年\\\")\",\"=FS_CELL(\\\"107.01.CL_BR_SDB\\\",\\\"原值-商业承兑汇票\\\",\\\"期初数|账项调整\\\",\\\"本年\\\")\",\"=F3-G3\",\"{\\\"rId\\\":\\\"b9646f1ce1e341b9a0d1fe0720dc302b\\\",\\\"r_tag\\\":[\\\"TOP--1468\\\"]}\"],[\"行|聚合|合计|合计\",\"合   计\",\"=IFERROR(SUM(C2:C3),0)\",\"=IFERROR(SUM(D2:D3),0)\",\"=IFERROR(SUM(E2:E3),0)\",\"=IFERROR(SUM(F2:F3),0)\",\"=IFERROR(SUM(G2:G3),0)\",\"=IFERROR(SUM(H2:H3),0)\",\"{\\\"rId\\\":\\\"db2cbbe247f4492ebe15d0ebc8a77b27\\\",\\\"r_polymeric\\\":{\\\"type\\\":\\\"SUM\\\",\\\"tags\\\":[\\\"TOP--1468\\\"],\\\"tagType\\\":\\\"top\\\"},\\\"operator_r\\\":{\\\"operatorTag\\\":\\\"row\\\"}}\"]],\"cellsMeta\":[{\"row\":0,\"col\":0},{\"row\":0,\"col\":1},{\"row\":0,\"col\":2},{\"row\":0,\"col\":3},{\"row\":0,\"col\":4},{\"row\":0,\"col\":5},{\"row\":0,\"col\":6},{\"row\":0,\"col\":7},{\"row\":0,\"col\":8},{\"row\":1,\"col\":0},{\"row\":1,\"col\":1},{\"row\":1,\"col\":2},{\"row\":1,\"col\":3},{\"row\":1,\"col\":4},{\"row\":1,\"col\":5},{\"row\":1,\"col\":6},{\"row\":1,\"col\":7},{\"row\":1,\"col\":8},{\"row\":2,\"col\":0},{\"row\":2,\"col\":1},{\"row\":2,\"col\":2},{\"row\":2,\"col\":3},{\"row\":2,\"col\":4},{\"row\":2,\"col\":5},{\"row\":2,\"col\":6},{\"row\":2,\"col\":7},{\"row\":2,\"col\":8},{\"row\":3,\"col\":0},{\"row\":3,\"col\":1,\"custom\":{\"bl\":2}},{\"row\":3,\"col\":2,\"custom\":{\"bl\":2}},{\"row\":3,\"col\":3,\"custom\":{\"bl\":2}},{\"row\":3,\"col\":4,\"custom\":{\"bl\":2}},{\"row\":3,\"col\":5,\"custom\":{\"bl\":2}},{\"row\":3,\"col\":6,\"custom\":{\"bl\":2}},{\"row\":3,\"col\":7,\"custom\":{\"bl\":2}},{\"row\":3,\"col\":8}],\"tableConfig\":\"{\\\"tableInfo\\\":{\\\"rowLen\\\":4,\\\"cellLen\\\":36,\\\"columnLen\\\":11,\\\"columnLeafLen\\\":9,\\\"type\\\":\\\"serer\\\"},\\\"formulaOff\\\":false,\\\"clearTable\\\":true,\\\"action\\\":\\\"clear\\\"}\",\"cpasDesc\":[],\"editDate\":\"2025-08-23T10:50:41.403Z\",\"updateFlag\":1,\"editUser\":\"【1】张某\",\"headerColumn\":[{\"key\":\"989f6a38b3a341e991d5df754d74ee54-key\",\"label\":\"主键\",\"config\":{\"width\":150,\"type\":\"autocomplete\",\"visibleRows\":10,\"strict\":false,\"className\":\"cpas-map-model\",\"columnIndex\":\"A\"},\"cmap\":\"主键\",\"level\":1,\"colspan\":1,\"type\":\"header\",\"pid\":\"\",\"rowspan\":2,\"index\":\"0_0\",\"pathLabel\":\"主键\"},{\"key\":\"42f0b1e27ca84ca0bb8894c06833d95f\",\"label\":\"票据种类\",\"config\":{\"width\":176,\"type\":\"text\",\"ht\":1,\"keyword\":true,\"bl\":2,\"columnIndex\":\"B\"},\"cmap\":\"票据种类\",\"level\":1,\"colspan\":1,\"type\":\"header\",\"pid\":\"\",\"rowspan\":2,\"index\":\"0_1\",\"pathLabel\":\"票据种类\"},{\"key\":\"1eef4a9029024465ac26aab95dfa0fca\",\"label\":\"账面余额\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2,\"columnIndex\":\"C\"},\"cmap\":\"期末数-账面余额\",\"level\":2,\"colspan\":1,\"type\":\"header\",\"rowspan\":1,\"index\":\"1_2\",\"pathLabel\":\"期末数-账面余额\"},{\"key\":\"d0865bbdb07b4c759d4a211026039b16\",\"label\":\"坏账准备\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2,\"columnIndex\":\"D\"},\"cmap\":\"期末数-坏账准备\",\"level\":2,\"colspan\":1,\"type\":\"header\",\"rowspan\":1,\"index\":\"1_3\",\"pathLabel\":\"期末数-坏账准备\"},{\"key\":\"d2831cac10234383b8bd9ecc0921bd81\",\"label\":\"账面价值\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2,\"columnIndex\":\"E\"},\"cmap\":\"期末数-账面价值\",\"level\":2,\"colspan\":1,\"type\":\"header\",\"rowspan\":1,\"index\":\"1_4\",\"pathLabel\":\"期末数-账面价值\"},{\"key\":\"09d80c626e95484d89acfef624ce5145\",\"label\":\"账面余额\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2,\"columnIndex\":\"F\"},\"cmap\":\"期初数-账面余额\",\"level\":2,\"colspan\":1,\"type\":\"header\",\"rowspan\":1,\"index\":\"1_5\",\"pathLabel\":\"期初数-账面余额\"},{\"key\":\"fe05f974750f4759b7fc1f989b55d616\",\"label\":\"坏账准备\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2,\"columnIndex\":\"G\"},\"cmap\":\"期初数-坏账准备\",\"level\":2,\"colspan\":1,\"type\":\"header\",\"rowspan\":1,\"index\":\"1_6\",\"pathLabel\":\"期初数-坏账准备\"},{\"key\":\"e3d9a409ca804966aa3b0818eb523162\",\"label\":\"账面价值\",\"config\":{\"type\":\"numeric\",\"width\":126,\"ht\":3,\"validator\":\"cpasFormulaValidator\",\"bl\":2,\"columnIndex\":\"H\"},\"cmap\":\"期初数-账面价值\",\"level\":2,\"colspan\":1,\"type\":\"header\",\"rowspan\":1,\"index\":\"1_7\",\"pathLabel\":\"期初数-账面价值\"},{\"key\":\"c24cb6f20d31426e8151ea607953e18e-config\",\"label\":\"rowConfig\",\"config\":{\"width\":150,\"type\":\"text\",\"columnIndex\":\"I\"},\"cmap\":\"rowConfig\",\"level\":1,\"colspan\":1,\"type\":\"header\",\"pid\":\"\",\"rowspan\":2,\"index\":\"0_8\",\"pathLabel\":\"rowConfig\"}],\"tname\":\"应收票据分类\",\"tType\":\"ds\",\"displayData\":[[\"\\\\\",\"票据种类\",\"期末-账面余额\",\"期末-坏账准备\",\"期末-账面价值\",\"期初-账面余额\",\"期初-坏账准备\",\"期初-账面价值\",\"{\\\"rId\\\":\\\"8bd173afb5b34fa2a5328e19b2238614\\\",\\\"className\\\":\\\"cpas-map-model\\\",\\\"type\\\":\\\"autocomplete\\\",\\\"visibleRows\\\":10,\\\"strict\\\":false}\"],[\"银行承兑汇票\",\"银行承兑汇票\",\"\",\"\",\"0\",\"\",\"\",\"0\",\"{\\\"rId\\\":\\\"d1b72f7572c8487fb435ae745421608f\\\",\\\"r_tag\\\":[\\\"TOP--1468\\\"]}\"],[\"商业承兑汇票\",\"商业承兑汇票\",\"\",\"\",\"0\",\"\",\"\",\"0\",\"{\\\"rId\\\":\\\"b9646f1ce1e341b9a0d1fe0720dc302b\\\",\\\"r_tag\\\":[\\\"TOP--1468\\\"]}\"],[\"行|聚合|合计|合计\",\"合   计\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"{\\\"rId\\\":\\\"db2cbbe247f4492ebe15d0ebc8a77b27\\\",\\\"r_polymeric\\\":{\\\"type\\\":\\\"SUM\\\",\\\"tags\\\":[\\\"TOP--1468\\\"],\\\"tagType\\\":\\\"top\\\"},\\\"operator_r\\\":{\\\"operatorTag\\\":\\\"row\\\"}}\"]],\"cpasVerify\":{\"tid\":null,\"dbname\":null,\"tableName\":\"\",\"type\":\"\",\"artVerifyFormulaItemList\":[],\"artParseResultList\":[]},\"tid\":\"974ff963818c56e4\"}";
        RowRenderData[] rowRenderData = buildPlaceholderData(a);*/


        RowRenderData row0 = Rows.of("姓名", "", "", "年纪", "", "", "哈哈", "", "")
                .textColor("FFFFFF")
                .rowHeight(50f)
                .bgColor("4472C4")
                .center()
                .create();
        RowRenderData row1 = Rows.create("李四", "博士", "清华大学", null, "博士1", "清华大学1", null, "大专2", "清华大学2");
        RowRenderData row2 = Rows.create("李四", "博士", "清华大学", null, "博士1", "清华大学1", null, "大专2", "清华大学2");

        MergeCellRule rule = MergeCellRule.builder().map(MergeCellRule.Grid.of(0, 0), MergeCellRule.Grid.of(0, 2))
                .map(MergeCellRule.Grid.of(0, 3), MergeCellRule.Grid.of(0, 5))
                .map(MergeCellRule.Grid.of(0, 6), MergeCellRule.Grid.of(0, 8))
                .build();


        Map<String, Object> datas = new HashMap<>();
        datas.put("审定财务资产表", Tables.of(row0, row1, row2).mergeRule(rule).create());

        XWPFTemplate template = XWPFTemplate.compile("G:\\222.docx");
        template.render(datas);
        template.writeAndClose(new FileOutputStream("G:\\output.docx"));

    }


}
